package com.mimiwang.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mimiwang.article.dao.ArticleCategoryRelationDao;
import com.mimiwang.article.entity.ArticleCategoryRelationEntity;
import com.mimiwang.article.service.ArticleCategoryRelationService;
import com.mimiwang.common.utils.PageUtils;
import com.mimiwang.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Map;


@Service("articleCategoryRelationService")
public class ArticleCategoryRelationServiceImpl extends ServiceImpl<ArticleCategoryRelationDao, ArticleCategoryRelationEntity> implements ArticleCategoryRelationService {

    @Autowired
    private ArticleCategoryRelationDao categoryRelationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ArticleCategoryRelationEntity> page = this.page(
                new Query<ArticleCategoryRelationEntity>().getPage(params),
                new QueryWrapper<ArticleCategoryRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveCategoryId(Long articleId, Long categoryId) {
        ArticleCategoryRelationEntity entity = new ArticleCategoryRelationEntity();
        entity.setArticleId(articleId);
        entity.setCategoryId(categoryId);
        int insert = categoryRelationDao.insert(entity);
    }

    /*根据文章id查询分类id*/
    @Override
    public ArrayList<Long> selectById(Long articleid) {
        categoryRelationDao.selectByArticleId(articleid);
        return null;
    }

}